<?php

namespace app\admin\controller;

use app\admin\model\Admin;
use app\admin\model\User;
use app\common\controller\Backend;
use app\admin\utils\PrinterUtil;
use app\common\model\Attachment;
use fast\Date;
use think\Db;
use think\Config;


/**
 * 打印机测试demo控制器
 *
 * @icon   fa fa-dashboard
 * @remark 用于展示点击测试
 */
class Printerdemo extends Backend
{
    protected $model = null;
    protected $noNeedRight = [];
    private $printerUtil = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->printerUtil = new PrinterUtil();
    }

    /**
     * 查询打印机状态
     */
    public function querystatus()
    {
        $this->printerUtil->queryPrinterStatus(Config::get('site')['SNCODE']);
    }
    
    /**
     * 测试打印
     */
    public function test()
    {
        $content = Config::get('site')['PRINT_TEMPLATE'];

        $replace_arr = [
            'title' =>'供奉佛灯测试',
            'name' =>'张三',
            'phone' =>'1511***443',
            'buddha' =>'文殊菩萨',
            'blessing' =>'祝明年财源广进，生意兴隆。',
            'timespan' =>'3个月',
            'money' =>'￥88',
            'time' => date('Y-m-d H:i:s', time()),
        ];
        foreach($replace_arr as $k=>$v){
            $content = str_replace('{' . $k . '}', $v, $content);
        }

        print_r($content);
        print_r($this->printerUtil->printMsg(Config::get('site')['SNCODE'], $content));
    }

}
